package pATT.DataSetsGenerator.dataSetsGenerator.core.implement;

public class Support {
	
	public static boolean isIntegerPositive(String text){
		if(!isDigit(text))
			return false;
		int aux = Integer.parseInt(text.trim());
		return aux > 0;
	} 
	
	public static boolean isDoublePositive(String text){
		if(!isDouble(text))
			return false;
		double aux = Double.valueOf(text.trim());
		return aux > 0.0;
	} 
	
	public static boolean minusIntegerThan(String text1, String text2){
		if(!isDigit(text1) || !isDigit(text2))
			return false;
		int aux1 = Integer.parseInt(text1.trim());
		int aux2 = Integer.parseInt(text2.trim());
	
		return aux1 <= aux2 ;
	}
	
	public static boolean minusRealThan(String text1, String text2){
		if(!isDouble(text1) || !isDouble(text2))
			return false;
		double aux1 = Double.parseDouble(text1.trim());
		double aux2 = Double.parseDouble(text2.trim());
	
		return aux1 <= aux2 ;
	}
	
	public static boolean isDigit(String text) {
		int pos = 0;
		text = text.trim();
		if(text.equals(""))
			return false;
		if(text.charAt(0) == '-')
			pos = 1;
		for (int i = pos; i < text.length(); i++) {
			if(!Character.isDigit(text.charAt(i)))
				return false;			
		}
		return true;
	}
	
	//verificar que tenga solo un punto
	public static boolean isDouble(String text) {
		int pos = 0;
		boolean countPoint = false;
		text = text.trim();
		if(text.equals(""))
			return false;
		if(text.charAt(0) == '-')
			pos = 1;
		for (int i = pos; i < text.length(); i++) {
			if(!Character.isDigit(text.charAt(i)))
				if(text.charAt(i) != '.' || countPoint)
					return false;
			if(text.charAt(i) == '.')
				countPoint = true;

		}
		return true;
	}

	public static boolean isValuesNominalCorrect(String text) {
		text = text.trim();
		if(text.equals(""))
			return false;
		for (int i = 0; i < text.length(); i++) {
			if(!Character.isLetterOrDigit(text.charAt(i)))
				if(text.charAt(i) != ',' && text.charAt(i) != '_')
					return false;
		}
		return true;
	}

}
